<?php
//@session_start();
/**
 * @author thihien
 * @copyright 2011
 */

$madanhmuc=$_GET['madanhmucsanpham'];
//$sql='select * from sanpham where madanhmuc='.$madanhmuc;
//$kq=tep_db_query($sql);
/* phan trang */
 $sql='SELECT count(id) as count FROM `tbl_san_pham` where ma_danh_muc='.$madanhmuc;
$kq=tep_db_query($sql);
$item1=tep_db_fetch_array($kq);
//bat dau viet phan trang
$display=15;// so san pham xuat hien tren mot trang
$record=$item1['count'];//tong so san pham
if($record>$display){
    $page=ceil($record/$display);
}
else{
    $page=1;
}
$start=isset($_GET['start']) && (int)$_GET['start']?$_GET['start']:0;
$sql4='select * from tbl_san_pham where ma_danh_muc='.$madanhmuc.' limit '.$start.', '.$display.'';
$kq4=tep_db_query($sql4);
 $content='';
/*ket thuc phan lay tong sp*/
$sql7='select * from tbl_danh_muc_san_pham where id='.$madanhmuc;
$kq7=tep_db_query($sql7);
$item4=tep_db_fetch_array($kq7);

$content.='
    <div id="main-content">
     <div id="sp_noibat">';
            require_once('services/danhmucsanpham.php');
            $danhmucsanphamService = new DanhmucsanphamService();
            $item1 = $danhmucsanphamService->getTendanhmuc($madanhmuc);  
            
        
        $content.='<div class="tieudetrang"><h2>'.$item1['ten_danh_muc'].'</h2></div>
        <div class="sp_noibat">';
            
                $sql='select * from tbl_san_pham where ma_danh_muc='.$madanhmuc;
                $kq=tep_db_query($sql);
                while($item=tep_db_fetch_array($kq)){
                $content.='<div  class="hinhanhsanpham">
                   <div class="h_a"><a href="'.DOMAIN_NAME.'/get/page/sanpham/masp/'.$item['id'].'/madanhmucsp/'.$item['ma_danh_muc'].'/mode/detail"><img src="'.PRODUCT_IMAGE_URL.$item['hinh_anh'].'" width="218" height="177" border="1px" /></a></div>
                     <div class="tensp">
                        <p><a href="'.DOMAIN_NAME.'/get/page/sanpham/masp/'.$item['id'].'/madanhmucsp/'.$item['ma_danh_muc'].'/mode/detail">'.$item['ten_san_pham'].'</a></p>
                        <p>Giá : '.number_format($item['gia']).' VNĐ</p>                                        
                        <p>NSX : '.$item['noi_san_xuat'].'<p>
                        <p style="padding-top: 5px;"><a href="javascript:buyProduct('.$item['id'].');"><img src="'.IMAGE_URL.'giohang.jpg" /></a><p>
                    </div>
                   </div>';
                   
                }
            
       $content.=' </div>
    

</div>';
        
$content.='<ul class="phantrang">';
             $content.='<span style="color:#7d171d;font-weight:bold;">Trang :</span>';
            if($page>1){
                $next=$start+$display;
                $prev=$start-$display;
                $current=($start/$display)+1;
                //hien thi phan trang prev
               
                if($current!=1){
                   $content.='<li><a href="'.DOMAIN_NAME.'/get/page/sanphamtheodanhmuc/madanhmucsanpham/'.$madanhmuc.'/start/'.$prev.'">Previous</a></li>'; 
                }
                 //hien thi trang
                 for($i=1;$i<=$page;$i++){
                   if($current!=$i){
                        $content.='<li><a href="'.DOMAIN_NAME.'/get/page/sanphamtheodanhmuc/madanhmucsanpham/'.$madanhmuc.'/start/'.$display*($i-1).'">'.$i.'</a></li>'; 
                    } 
                    else
                    {
                       $content.='<li class="current"><a href="'.DOMAIN_NAME.'/get/page/sanphamtheodanhmuc/madanhmucsanpham/'.$madanhmuc.'/start/'.$display*($i-1).'">'.$i.'</a></li>'; 
                    }
                     
                 }
                //hien thi next
                if($current!=$page){
                    $content.='<li><a href="'.DOMAIN_NAME.'/get/page/sanphamtheodanhmuc/madanhmucsanpham/'.$madanhmuc.'/start/'.$next.'">Next</a></li>';  
                }
            }
            else{
                $content.='<li class="current"><a href="'.DOMAIN_NAME.'/get/page/sanphamtheodanhmuc/madanhmucsanpham/'.$madanhmuc.'/start/0">'.$page.'</a></li>';  
            }
       $content.=' </ul>';
        
      
   $content.='
    </div> 
';
echo $content;


?>